package com.zxcrm.web.controller.zxcrm;

import com.zxcrm.common.annotation.Log;
import com.zxcrm.common.core.controller.BaseController;
import com.zxcrm.common.core.domain.AjaxResult;
import com.zxcrm.common.core.page.TableDataInfo;
import com.zxcrm.common.enums.BusinessType;
import com.zxcrm.common.utils.poi.ExcelUtil;
import com.zxcrm.zxcrm.domain.ZxcrmScore;
import com.zxcrm.zxcrm.service.IZxcrmScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分表Controller
 * 
 * @author xu
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/zxcrm/score")
public class ZxcrmScoreController extends BaseController
{
    @Autowired
    private IZxcrmScoreService zxcrmScoreService;

    /**
     * 查询评分表列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxcrmScore zxcrmScore)
    {
        startPage();
        List<ZxcrmScore> list = zxcrmScoreService.selectZxcrmScoreList(zxcrmScore);
        return getDataTable(list);
    }

    /**
     * 查询评分表列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:list')")
    @GetMapping("/listUserScore")
    public TableDataInfo listUserScore(ZxcrmScore zxcrmScore)
    {
        startPage();
        List<ZxcrmScore> list = zxcrmScoreService.selectZxcrmScoreListUserScore(zxcrmScore);
        return getDataTable(list);
    }

    /**
     * 查询评分统计表列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:list')")
    @GetMapping("/scoreStatisticsDetailList")
    public AjaxResult scoreStatisticsDetailList(ZxcrmScore zxcrmScore)
    {
        List<ZxcrmScore> list = zxcrmScoreService.scoreStatisticsDetailList(zxcrmScore);
        return AjaxResult.success(list);
    }

    /**
     * 导出评分表列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:export')")
    @Log(title = "评分表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxcrmScore zxcrmScore)
    {
        List<ZxcrmScore> list = zxcrmScoreService.selectZxcrmScoreList(zxcrmScore);
        ExcelUtil<ZxcrmScore> util = new ExcelUtil<ZxcrmScore>(ZxcrmScore.class);
        util.exportExcel(response, list, "评分表数据");
    }

    /**
     * 获取评分表详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zxcrmScoreService.selectZxcrmScoreById(id));
    }

    /**
     * 获取被评分人评分表详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:query')")
    @GetMapping(value = "/listUserScoreByUserId/{userId}")
    public AjaxResult listUserScoreByUserId(@PathVariable("userId") Long userId)
    {
        return success(zxcrmScoreService.listUserScoreByUserId(userId));
    }

    /**
     * 新增评分表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:add')")
    @Log(title = "评分表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxcrmScore zxcrmScore)
    {
        return toAjax(zxcrmScoreService.insertZxcrmScore(zxcrmScore));
    }

    /**
     * 新增评分表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:add')")
    @Log(title = "评分表", businessType = BusinessType.INSERT)
    @PostMapping("/score" )
    public AjaxResult score(@RequestBody ZxcrmScore zxcrmScore)
    {
        return toAjax(zxcrmScoreService.score(zxcrmScore));
    }

    /**
     * 修改评分表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:edit')")
    @Log(title = "评分表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxcrmScore zxcrmScore)
    {
        return toAjax(zxcrmScoreService.updateZxcrmScore(zxcrmScore));
    }

    /**
     * 删除评分表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:score:remove')")
    @Log(title = "评分表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zxcrmScoreService.deleteZxcrmScoreByIds(ids));
    }
}
